//安全帽模块
const { ethers, upgrades } = require('hardhat')

async function main() {
  const UUPSV1 = await ethers.getContractFactory('UUPSV1')

  // 部署合约, 并调用初始化方法
  const myUUPSV1 = await upgrades.deployProxy(UUPSV1, {
    initializer: 'initialize',
    kind: 'uups',
  })

  await myUUPSV1.waitForDeployment()

  // 代理合约地址
  const proxyAddress = myUUPSV1.target
  // 实现合约地址
  const implementationAddress = await upgrades.erc1967.getImplementationAddress(
    proxyAddress,
  )
  // proxyAdmin 合约地址
  const adminAddress = await upgrades.erc1967.getAdminAddress(proxyAddress)

  console.log(`proxyAddress: ${proxyAddress}`)
  console.log(`implementationAddress: ${implementationAddress}`)
  // Warning: A proxy admin was previously deployed on this network
  //  // 管理员合约实际不存在了，只有代理合约和实现合约
  console.log(`adminAddress: ${adminAddress}`)
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error)
    process.exit(1)
  })
